package com.ruoyi.party.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.party.system.domain.Ad;
import com.ruoyi.party.system.service.IAdService;
import com.ruoyi.party.system.service.IMemberService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 党员宣传报道登记Controller
 * 
 * @author 黄宝康
 * @date 2021-04-19
 */
@Controller
@RequestMapping("/business/ad")
public class AdController extends BaseController
{
    private String prefix = "business/ad";

    @Autowired
    private IAdService adService;
    @Autowired
    private IMemberService memberService;

    @RequiresPermissions("business:ad:view")
    @GetMapping()
    public String ad(ModelMap mmap)
    {
    	// 获取所有党员，用于列表搜索查询
    	mmap.put("members", memberService.selectMemberList(null));
        return prefix + "/ad";
    }

    /**
     * 查询党员宣传报道登记列表
     */
    @RequiresPermissions("business:ad:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Ad ad)
    {
        startPage();
        List<Ad> list = adService.selectAdList(ad);
        return getDataTable(list);
    }

    /**
     * 导出党员宣传报道登记列表
     */
    @RequiresPermissions("business:ad:export")
    @Log(title = "党员宣传报道登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Ad ad)
    {
        List<Ad> list = adService.selectAdList(ad);
        ExcelUtil<Ad> util = new ExcelUtil<Ad>(Ad.class);
        return util.exportExcel(list, "党员宣传报道登记数据");
    }

    /**
     * 新增党员宣传报道登记
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
    	mmap.put("members", memberService.selectMemberList(null));
        return prefix + "/add";
    }

    /**
     * 新增保存党员宣传报道登记
     */
    @RequiresPermissions("business:ad:add")
    @Log(title = "党员宣传报道登记", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated Ad ad)
    {
        return toAjax(adService.insertAd(ad));
    }

    /**
     * 修改党员宣传报道登记
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Ad ad = adService.selectAdById(id);
        mmap.put("members", memberService.selectMemberList(null));
        mmap.put("ad", ad);
        return prefix + "/edit";
    }

    /**
     * 修改保存党员宣传报道登记
     */
    @RequiresPermissions("business:ad:edit")
    @Log(title = "党员宣传报道登记", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated Ad ad)
    {
        return toAjax(adService.updateAd(ad));
    }

    /**
     * 删除党员宣传报道登记
     */
    @RequiresPermissions("business:ad:remove")
    @Log(title = "党员宣传报道登记", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(adService.deleteAdByIds(ids));
    }
}
